| Conditions | 4 |
| Total Lines | 22 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import ResponseInterceptor from './response-interceptor' |
||
| 9 | |||
| 10 | /** |
||
| 11 | * If the error is 401 for token expired try to renew tokens re-send the original request. |
||
| 12 | * |
||
| 13 | * @param error The original error. |
||
| 14 | */ |
||
| 15 | public async errorHandler(error: any): Promise<any> { |
||
| 16 | if (!error.response || !this.isTokenExpired(error.response)) { |
||
| 17 | // Not an expired token's fault. |
||
| 18 | if (error.response?.status === 401) { // if 401 clear tokens |
||
| 19 | const storage = this.beditaClient.getStorageService(); |
||
| 20 | await storage.clearTokens(); |
||
| 21 | await storage.remove('user'); |
||
| 22 | } |
||
| 23 | |||
| 24 | return Promise.reject(error); |
||
| 25 | } |
||
| 26 | |||
| 27 | await this.beditaClient.renewTokens(); |
||
| 28 | delete error.config.headers.Authorization; |
||
| 29 | |||
| 30 | return await this.beditaClient.request(error.config); |
||
| 31 | } |
||
| 44 |